export default {
  namespaced: true,
  state: {
    // 用户的收货地址
    address: JSON.parse(uni.getStorageSync('address') || '{}'),
    // 登录令牌
    token: uni.getStorageSync('token') || '',
    // 用户的基本信息
    userinfo: JSON.parse(uni.getStorageSync('userinfo') || '{}'),
    // 重定向页面信息对象--{ opentype，from }
    redirectInfo: null
  },
  mutations: {
    saveAddress(state, obj) {
      state.address = {...obj};
      uni.setStorageSync('address', JSON.stringify(state.address))
    },
    saveToken(state, str) {
      state.token = str;
      uni.setStorageSync('token', state.token)
    },
    saveUserInfo(state, obj) {
      state.userinfo = {...obj};
      uni.setStorageSync('userinfo', JSON.stringify(state.userinfo))
    },
    // 设置重定向数据
    updateRedirectInfo(state, obj) {
      state.redirectInfo = obj;
      console.log('重定向数据', state.redirectInfo);
    }
  },
  actions: {},
  getters: {
    // 收货地址：多个字符的拼接
    addstr(state) {
      return `${state.address.provinceName}${state.address.cityName}${state.address.countyName}${state.address.detailInfo}`;
    } 
  },
}